package userlogic

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/login-rpc/internal/dao/model"

	"gitee.com/liuxuezhan/ar-platform/login-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/login-rpc/login_rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CheckIpNumLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCheckIpNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckIpNumLogic {
	return &CheckIpNumLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CheckIpNumLogic) CheckIpNum(in *login_rpc.CheckIpNumRequest) (*login_rpc.CheckIPNumResponse, error) {
	t, err := model.NewUserModel(l.ctx, l.svcCtx.Db).GetIPNumByIP(in.Ip)
	if err != nil {
		return nil, err
	}
	return &login_rpc.CheckIPNumResponse{
		Num: int32(t),
	}, nil
}
